//
//  WJNavigationVC.swift
//  新浪微博swift
//
//  Created by WJ-Jason on 2017/5/1.
//  Copyright © 2017年 WJ-Jason. All rights reserved.
//

import UIKit

class WJNavigationVC: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        //隐藏默认的navigationbar
        navigationBar.isHidden = true
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        print("当前的VC为: " , viewController,childViewControllers.count)
        
        //重写push方法隐藏底部Tabbar
        if childViewControllers.count > 0  {
           viewController.hidesBottomBarWhenPushed = true
        }
        
        //判断控制器的类型
        if let vc = viewController as? WJBaseVC {
            var title = "返回"
            
            //判断控制器的级数,只有一个控制器的时候,显示栈底控制器的标题
            if childViewControllers.count <= 1 {
                title = childViewControllers.first?.title ?? ""
            }
            
            vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, style:.plain, target: self, action: #selector(pooToParent))
        }
        
        
        super.pushViewController(viewController, animated: animated)
    }
    
    ///pop返回上一级口控制器
    @objc private func pooToParent () {
        popViewController(animated: true)
    }
    

}
